package com.fasteat.search.service.impl;

import com.fasteat.search.entity.Page;
import com.fasteat.search.entity.SearchCondition;
import com.fasteat.search.service.MenuSearchService;
import com.fasteat.search.template.MenuSearch;
import com.fasteat.search.util.SearchUtil;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MenuSearchServiceImpl implements MenuSearchService {

	@Autowired
	private MenuSearch menuSearch;

	@Override
	public Page searchWithHighlightAndPageAndSort(SearchCondition condition, Map<String, SortOrder> sortMap) {
		return menuSearch
				.highlight(SearchUtil.highlightBuilder(condition.getEntry().keySet(),
						"<span style='color:orange'>",
						"</span>"))
				.sort(sortMap)
				.search(condition);
	}

	@Override
	public boolean removeMenuById(String id) {
		return menuSearch.delete(id);
	}
}
